package com.wk.data.tree;

import java.util.List;

/**
 * 求树深度
 * @author wukai
 * @date 2023/5/5 17:11
 */
public class TreeDepth {
    public static void main(String[] args) {
        TreeNode head = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(3);
        head.left = node1;
        head.right = node2;
        TreeNode node3 = new TreeNode(4);
        TreeNode node4 = new TreeNode(2);
        TreeNode node5 = new TreeNode(4);
        node1.left = node3;
        node2.left = node4;
        node2.right = node5;
        TreeNode node6 = new TreeNode(4);
        node4.left = node6;
        System.out.println(maxDepth(head));
    }

    private static int maxDepth(TreeNode head) {
        if(head == null){
            return 0;
        }
        return Math.max(maxDepth(head.left),maxDepth(head.right))+1;
    }
}
